package com.brook.app.android.filepicker.util;

import java.lang.ref.SoftReference;

/**
 * 软引用单利
 *
 * @param <T>
 */
public abstract class SoftReferenceSingleton<T> {


    private volatile SoftReference<T> mInstance;

    public SoftReferenceSingleton() {

    }

    protected abstract T create();

    public T getInstance() {
        if (mInstance == null || mInstance.get() == null) {
            synchronized (this) {
                if (mInstance == null || mInstance.get() == null) {
                    mInstance = new SoftReference<>(create());
                }
            }
        }
        return mInstance.get();
    }
}
